﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Okuma.CLDATAPI.DataAPI;
using Okuma.CLDATAPI.Enumerations;
using OpenNETCF.MTConnect;

namespace Okuma
{
    public class Program : ToolPart
    {
        private CProgram m_program;

        public override ComponentType ComponentType
        {
            get { return OpenNETCF.MTConnect.ComponentType.Path; }
        }

        public override string Name
        {
            get { return "Program"; }
        }

        internal Program(SubSystemEnum subSystem)
            : base(subSystem)
        {
            m_program = new CProgram(subSystem);
        }

        [EventDataItem(
            ItemType = DataItemType.PROGRAM
            )]
        public string ActiveProgramName
        {
            get { return m_program.GetActiveProgramName(); }
        }

        [EventDataItem(
            ItemType = DataItemType.PROGRAM
        )]
        public string ActiveProgramFile
        {
            get { return m_program.GetActiveProgramFileName(); }
        }

        [EventDataItem(
            ItemType = DataItemType.BLOCK
        )]
        public string ExecuteBlock
        {
            get { return m_program.GetExecuteBlock(); }
        }

        [EventDataItem(
            ItemType = DataItemType.MOTION_PROGRAM
        )]
        public string ExecutedSequenceNumber
        {
            get { return m_program.GetExecutedSequenceNumber(); }
        }

        [EventDataItem(
            ItemType = DataItemType.LINE
            )]
        public int CurrentBlockNumber
        {
            get { return m_program.GetCurrentBlockNumber(); }
        }

        [EventDataItem]
        public bool LeftIsCycleComplete
        {
            get
            {
                try
                {
                    return m_program.CycleComplete(MachineSideEnum.LeftSide);
                }
                catch
                {
                    return false;
                }
            }
        }

        [EventDataItem]
        public bool RightIsCycleComplete
        {
            get 
            {
                try
                {
                    return m_program.CycleComplete(MachineSideEnum.RightSide);
                }
                catch
                {
                    return false;
                }
            }
        }

        [EventDataItem(
            ItemType = DataItemType.EXECUTION
            )]
        public string LeftRunningState
        {
            get 
            {
                try
                {
                    return m_program.GetProgramRunningState(MachineSideEnum.LeftSide).ToString();
                }
                catch
                {
                    return string.Empty;
                }
            }
        }

        [EventDataItem(
            ItemType = DataItemType.EXECUTION
            )]
        public string RightRunningState
        {
            get
            {
                try
                {
                    return m_program.GetProgramRunningState(MachineSideEnum.RightSide).ToString();
                }
                catch
                {
                    return string.Empty;
                }
            }
        }
    }
}
